﻿using GrainManage.Entities.Weather;
using GrainManage.Proxy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace GrainManage.Web.Controllers
{
    public class WeatherController : BaseController
    {
        [HttpPost]
        public ActionResult GetRootWeather()
        {
            var inputPara = new InputGetChinaRootWeather
            {
                Authentication = CurrentAccount
            };
            var weatherProxy = ObjectFactory.WeatherProxy;
            var result = weatherProxy.GetChinaRootWeather(inputPara);

            if (Request.IsAjaxRequest())
            {
                return NewtonsoftJson(result);
            }
            return View(Constant.RestStatusView, result);
        }

        [HttpPost]
        public ActionResult GetCityWeather(string nameOrPinyin)
        {
            var inputPara = new InputGetChinaCityWeather
            {
                Authentication = CurrentAccount,
                NameOrPinyin = nameOrPinyin
            };
            var weatherProxy = ObjectFactory.WeatherProxy;
            var result = weatherProxy.GetChinaCityWeather(inputPara);

            if (Request.IsAjaxRequest())
            {
                return NewtonsoftJson(result);
            }
            return View(Constant.RestStatusView, result);
        }

        [HttpPost]
        public ActionResult GetCurrentWeather(string nameOrCode)
        {
            var inputPara = new InputGetChinaCurrentWeather
            {
                Authentication = CurrentAccount,
                NameOrCode = nameOrCode
            };
            var weatherProxy = ObjectFactory.WeatherProxy;
            var result = weatherProxy.GetChinaCurrentWeather(inputPara);

            if (Request.IsAjaxRequest())
            {
                return NewtonsoftJson(result);
            }
            return View(Constant.RestStatusView, result);
        }

        [HttpPost]
        public ActionResult GetNext7DayWeather(string nameOrCode)
        {
            var inputPara = new InputGetChinaNext7DayWeather
            {
                Authentication = CurrentAccount,
                NameOrCode = nameOrCode
            };
            var weatherProxy = ObjectFactory.WeatherProxy;
            var result = weatherProxy.GetChinaNext7DayWeather(inputPara);

            if (Request.IsAjaxRequest())
            {
                return NewtonsoftJson(result);
            }
            return View(Constant.RestStatusView, result);
        }
    }
}
